﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_SYS_GROUP
	/// </summary>
	public partial class DAL_T_SYS_GROUP
	{
		public DAL_T_SYS_GROUP()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string SYS_GROUP_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_SYS_GROUP");
			strSql.Append(" where SYS_GROUP_ID=:SYS_GROUP_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_GROUP_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_GROUP_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_SYS_GROUP model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_SYS_GROUP(");
			strSql.Append("SYS_GROUP_ID,DECODE,LEVEL_NO,NAME,PARENT_ID,AREA_ID,AREA_NAME,SEQ_NO,CREATE_TIME,CREATOR_ID,CREATOR_NAME,UPDATE_TIME,UPDATOR_ID,UPDATOR_NAME)");
			strSql.Append(" values (");
			strSql.Append(":SYS_GROUP_ID,:DECODE,:LEVEL_NO,:NAME,:PARENT_ID,:AREA_ID,:AREA_NAME,:SEQ_NO,:CREATE_TIME,:CREATOR_ID,:CREATOR_NAME,:UPDATE_TIME,:UPDATOR_ID,:UPDATOR_NAME)");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_GROUP_ID", OracleType.VarChar,40),
					new OracleParameter(":DECODE", OracleType.VarChar,500),
					new OracleParameter(":LEVEL_NO", OracleType.Number,4),
					new OracleParameter(":NAME", OracleType.VarChar,100),
					new OracleParameter(":PARENT_ID", OracleType.VarChar,40),
					new OracleParameter(":AREA_ID", OracleType.VarChar,40),
					new OracleParameter(":AREA_NAME", OracleType.VarChar,255),
					new OracleParameter(":SEQ_NO", OracleType.Number,4),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":CREATOR_NAME", OracleType.VarChar,100),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATOR_NAME", OracleType.VarChar,100)};
			parameters[0].Value = model.SYS_GROUP_ID;
			parameters[1].Value = model.DECODE;
			parameters[2].Value = model.LEVEL_NO;
			parameters[3].Value = model.NAME;
			parameters[4].Value = model.PARENT_ID;
			parameters[5].Value = model.AREA_ID;
			parameters[6].Value = model.AREA_NAME;
			parameters[7].Value = model.SEQ_NO;
			parameters[8].Value = model.CREATE_TIME;
			parameters[9].Value = model.CREATOR_ID;
			parameters[10].Value = model.CREATOR_NAME;
			parameters[11].Value = model.UPDATE_TIME;
			parameters[12].Value = model.UPDATOR_ID;
			parameters[13].Value = model.UPDATOR_NAME;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_SYS_GROUP model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_SYS_GROUP set ");
			strSql.Append("DECODE=:DECODE,");
			strSql.Append("LEVEL_NO=:LEVEL_NO,");
			strSql.Append("NAME=:NAME,");
			strSql.Append("PARENT_ID=:PARENT_ID,");
			strSql.Append("AREA_ID=:AREA_ID,");
			strSql.Append("AREA_NAME=:AREA_NAME,");
			strSql.Append("SEQ_NO=:SEQ_NO,");
			strSql.Append("CREATE_TIME=:CREATE_TIME,");
			strSql.Append("CREATOR_ID=:CREATOR_ID,");
			strSql.Append("CREATOR_NAME=:CREATOR_NAME,");
			strSql.Append("UPDATE_TIME=:UPDATE_TIME,");
			strSql.Append("UPDATOR_ID=:UPDATOR_ID,");
			strSql.Append("UPDATOR_NAME=:UPDATOR_NAME");
			strSql.Append(" where SYS_GROUP_ID=:SYS_GROUP_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DECODE", OracleType.VarChar,500),
					new OracleParameter(":LEVEL_NO", OracleType.Number,4),
					new OracleParameter(":NAME", OracleType.VarChar,100),
					new OracleParameter(":PARENT_ID", OracleType.VarChar,40),
					new OracleParameter(":AREA_ID", OracleType.VarChar,40),
					new OracleParameter(":AREA_NAME", OracleType.VarChar,255),
					new OracleParameter(":SEQ_NO", OracleType.Number,4),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":CREATOR_NAME", OracleType.VarChar,100),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATOR_NAME", OracleType.VarChar,100),
					new OracleParameter(":SYS_GROUP_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.DECODE;
			parameters[1].Value = model.LEVEL_NO;
			parameters[2].Value = model.NAME;
			parameters[3].Value = model.PARENT_ID;
			parameters[4].Value = model.AREA_ID;
			parameters[5].Value = model.AREA_NAME;
			parameters[6].Value = model.SEQ_NO;
			parameters[7].Value = model.CREATE_TIME;
			parameters[8].Value = model.CREATOR_ID;
			parameters[9].Value = model.CREATOR_NAME;
			parameters[10].Value = model.UPDATE_TIME;
			parameters[11].Value = model.UPDATOR_ID;
			parameters[12].Value = model.UPDATOR_NAME;
			parameters[13].Value = model.SYS_GROUP_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string SYS_GROUP_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_SYS_GROUP ");
			strSql.Append(" where SYS_GROUP_ID=:SYS_GROUP_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_GROUP_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_GROUP_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string SYS_GROUP_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_SYS_GROUP ");
			strSql.Append(" where SYS_GROUP_ID in ("+SYS_GROUP_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_SYS_GROUP GetModel(string SYS_GROUP_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SYS_GROUP_ID,DECODE,LEVEL_NO,NAME,PARENT_ID,AREA_ID,AREA_NAME,SEQ_NO,CREATE_TIME,CREATOR_ID,CREATOR_NAME,UPDATE_TIME,UPDATOR_ID,UPDATOR_NAME from T_SYS_GROUP ");
			strSql.Append(" where SYS_GROUP_ID=:SYS_GROUP_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_GROUP_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_GROUP_ID;

			ChinaSoft.Model.Model_T_SYS_GROUP model=new ChinaSoft.Model.Model_T_SYS_GROUP();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["SYS_GROUP_ID"]!=null && ds.Tables[0].Rows[0]["SYS_GROUP_ID"].ToString()!="")
				{
					model.SYS_GROUP_ID=ds.Tables[0].Rows[0]["SYS_GROUP_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["DECODE"]!=null && ds.Tables[0].Rows[0]["DECODE"].ToString()!="")
				{
					model.DECODE=ds.Tables[0].Rows[0]["DECODE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LEVEL_NO"]!=null && ds.Tables[0].Rows[0]["LEVEL_NO"].ToString()!="")
				{
					model.LEVEL_NO=decimal.Parse(ds.Tables[0].Rows[0]["LEVEL_NO"].ToString());
				}
				if(ds.Tables[0].Rows[0]["NAME"]!=null && ds.Tables[0].Rows[0]["NAME"].ToString()!="")
				{
					model.NAME=ds.Tables[0].Rows[0]["NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PARENT_ID"]!=null && ds.Tables[0].Rows[0]["PARENT_ID"].ToString()!="")
				{
					model.PARENT_ID=ds.Tables[0].Rows[0]["PARENT_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AREA_ID"]!=null && ds.Tables[0].Rows[0]["AREA_ID"].ToString()!="")
				{
					model.AREA_ID=ds.Tables[0].Rows[0]["AREA_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AREA_NAME"]!=null && ds.Tables[0].Rows[0]["AREA_NAME"].ToString()!="")
				{
					model.AREA_NAME=ds.Tables[0].Rows[0]["AREA_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SEQ_NO"]!=null && ds.Tables[0].Rows[0]["SEQ_NO"].ToString()!="")
				{
					model.SEQ_NO=decimal.Parse(ds.Tables[0].Rows[0]["SEQ_NO"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_TIME"].ToString()!="")
				{
					model.CREATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATOR_ID"]!=null && ds.Tables[0].Rows[0]["CREATOR_ID"].ToString()!="")
				{
					model.CREATOR_ID=ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATOR_NAME"]!=null && ds.Tables[0].Rows[0]["CREATOR_NAME"].ToString()!="")
				{
					model.CREATOR_NAME=ds.Tables[0].Rows[0]["CREATOR_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString()!="")
				{
					model.UPDATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_ID"]!=null && ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString()!="")
				{
					model.UPDATOR_ID=ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_NAME"]!=null && ds.Tables[0].Rows[0]["UPDATOR_NAME"].ToString()!="")
				{
					model.UPDATOR_NAME=ds.Tables[0].Rows[0]["UPDATOR_NAME"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SYS_GROUP_ID,DECODE,LEVEL_NO,NAME,PARENT_ID,AREA_ID,AREA_NAME,SEQ_NO,CREATE_TIME,CREATOR_ID,CREATOR_NAME,UPDATE_TIME,UPDATOR_ID,UPDATOR_NAME ");
			strSql.Append(" FROM T_SYS_GROUP ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_SYS_GROUP ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.SYS_GROUP_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_SYS_GROUP T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_SYS_GROUP";
			parameters[1].Value = "SYS_GROUP_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

